﻿
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static JSON_Test.Program;

namespace JSON_Test
{
    /// <summary>
    /// 使用选项的方式读取配置
    /// </summary>
    internal class TestController
    {
        private readonly IOptionsSnapshot<Config> optConfig;
        public TestController(IOptionsSnapshot<Config> optConfig)
        {
            this.optConfig = optConfig;
        }

        public void Test()
        {
            var config = optConfig.Value;
            Console.WriteLine(config.Name);
            Console.WriteLine(config.Age);
            Console.WriteLine(config.Proxy.Ip);
            Console.WriteLine(config.Proxy.Port);
        }
    }

    internal class TestController2
    {
        private readonly IOptionsSnapshot<Proxy> optProxy;
        public TestController2(IOptionsSnapshot<Proxy> optProxy)
        {
            this.optProxy = optProxy;
        }

        public void Test()
        {  
            Console.WriteLine(optProxy.Value.Ip);
            Console.WriteLine(optProxy.Value.Port);
        }
    }
}
